﻿@model List<WorkTimePrj.Controllers.ItemController.UserRoleModel>
@{
    Layout = null;
}
<!DOCTYPE html>
<html>
<head>
    <title>数据修复</title>
    <link href="@Url.Content("~/Content/css/Basic.css")" rel="stylesheet" type="text/css" />
    <link href="@Url.Content("~/Content/css/usecss.css")" rel="stylesheet" type="text/css" />
    <link href="@Url.Content("~/Content/css/mgmt.css")" rel="stylesheet" type="text/css" />
    <link href="@Url.Content("~/Content/themes/base/jquery.ui.all.css")" rel="stylesheet" type="text/css" />
    <script src="@Url.Content("~/Scripts/jquery-1.7.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery-ui-1.8.11.min.js")" type="text/javascript"></script>
    <style>
        td span { display: none; }
        td label { color: Red; }
    </style>
</head>
<body>
    <div id="layout" class="layout">
        <div style="text-align: center">
            <input type="button" value="修     复" class="Button01" style="line-height: 30px; height: 30px;
                margin-top: 2px;" id="txtMend" name="txtMend" class="Button01" onclick="repair()" />
        </div>
        <table id="tbl" width="100%" cellpadding="4" cellspacing="4" border="1" style="border-collapse: collapse">
            <tr>
                <th align="center" width="200">
                    账号
                </th>
                <th align="center" width="200">
                    姓名
                </th>
                <th align="center">
                    角色
                </th>
            </tr>
            @foreach (WorkTimePrj.Controllers.ItemController.UserRoleModel item in Model)
            {
                <tr>
                    <td style="text-align: center;">
                        @item.UserName
                    </td>
                    <td style="text-align: center;">
                        @item.Display
                    </td>
                    <td style="text-align: center;">
                        <select id="@item.UserName" name="@item.UserName" >
                        </select><span>@item.RoleID</span><label></label>
                    </td>
                </tr>
            }
        </table>
    </div>
    <script>
     var r = @ViewBag.Roles;
        $(document).ready(function () {
            $("#tbl > tbody >tr >td > select ").each(function () {
                var obj = $(this);
                obj.append("<option value=''>请选择</option>");
                for (var i = 0; i < r.length; i++) {
                    obj.append("<option value='" + r[i].RoleID + "'>" + r[i].Display + "</option>");
                }
                obj.val(obj.next().html());
            });


        });
        function repair() {
            document.getElementById('txtMend').disabled = true;
            var isvalid = true;
            var params = '';
            $("#tbl > tbody >tr >td > select ").each(function () {
                $(this).next().next().html('');
                if ($(this).val() == '') {
                    isvalid = false;
                    $(this).next().next().html('请选择');
                }
                else {
                    params += $(this).attr("id") + "=" + this.options[this.selectedIndex].text + "&";
                }

            });
            if (isvalid) {

                $.ajax({
                    url: "repair",
                    type: "POST",
                    data: { ps: params,'nc':Math.random() },
                    dataType: "json",
                    success: function (text) { alert('成功'); document.getElementById('txtMend').disabled = false; },
                    error: function (e) { alert('失败'); document.getElementById('txtMend').disabled = false; }
                });
            }
            else
            document.getElementById('txtMend').disabled = false;
        }
    </script>
</body>
</html>
